package com.zhengping.zpys.security.role;

import com.zhengping.zpys.base.AjaxResult;
import com.zhengping.zpys.security.log.Log;
import com.zhengping.zpys.security.log.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * @author xiaonuolen
 * @version 1.0
 * @date 2020/3/27 10:36
 */
@RestController
@RequestMapping("/monitor/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @Autowired
    private LogService logService;

    /**
     * 根据查询
     * @param role
     * @return
     */
    @GetMapping("/queryList")
    public AjaxResult queryList(@RequestBody(required = false) Role role){

        List<Role> roles = roleService.queryList(role);

        return AjaxResult.success(roles);
    }

    /**
     * @author chenweizuan
     * @description     根据id批量删除角色
     * @param roles   删除的角色列表
     * @return com.zhengping.zpys.base.AjaxResult   Integer 返回受影响的行数
     * @version 1.0
     * @date 2020/3/27 15:05
     */
    @PostMapping("/deleteList")
    public AjaxResult deleteList(@RequestBody(required = false) Long[] roles){

        Integer row = roleService.deleteList(roles);

        return AjaxResult.success(row);
    }

    /**
     * @author chenweizuan
     * @description     添加角色
     * @param role    添加的角色信息
     * @return com.zhengping.zpys.base.AjaxResult   Integer 返回是否成功
     * @version 1.0
     * @date 2020/3/27 15:55
     */
    @PostMapping("/creatRole")
    public AjaxResult creatRole(@RequestBody(required = false) Role role){
        Integer row = roleService.creatRole(role);
        return AjaxResult.success(row);
    }

    @PostMapping("/updateRole")
    public AjaxResult updateRole(@RequestBody(required = false) Role role){
        Integer row = roleService.updateRole(role);
        return AjaxResult.success(row);
    }

    @GetMapping("/queryRoleById")
    public AjaxResult queryRoleById(@RequestParam(required = false) Long roleId){
        Role role = roleService.queryRoleById(roleId);
        return AjaxResult.success(role);
    }

}
